package com.car.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.client.RestTemplate;

import com.car.entity.Image;
import com.car.entity.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Controller
public class testController {
	
	@Autowired
	 private RestTemplate restTemplate;
	

	private static final Logger logger = LoggerFactory.getLogger(testController.class);

	
	@HystrixCommand(fallbackMethod="backMethod")
	@GetMapping("/index")
	public String toindex(Model model){
		logger.info("执行查询，调用user登陆服务");
		User user = restTemplate.getForEntity("http://SERVER-WEB/users/h5Logins",User.class).getBody();
		logger.info("执行调用结束");
		model.addAttribute("user", user);
		return "homePage";
	}
	public String backMethod(Model model){
		model.addAttribute("user", "服务不可用，请稍后重试");
		return "homePage";
	}
	
	

}
